<template>
  <div class="app-container" v-loading="loading">
    <div class="filter-container">
      <el-select
        v-model="queryList.status"
        collapse-tags
        placeholder="请选择"
        class="filter-item">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.name"
          :value="item.value">
        </el-option>
      </el-select>
      <el-button type="primary" icon="el-icon-search" class="filter-item" @click="search">搜索</el-button>
      <!--<el-button class="filter-item" @click="reset">重置</el-button>-->
    </div>
    <div class="action-container">
      <el-button icon="el-icon-refresh" size="small" @click="refresh">刷新</el-button>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="withdrawAccount.withdrawWay.name"
        label=" 收款途径">
      </el-table-column>
      <el-table-column
        prop="withdrawAccount.payee"
        label="收款人">
      </el-table-column>
      <el-table-column
        prop="withdrawAccount.name"
        label="收款账号">
      </el-table-column>
      <el-table-column
        label="提现金额">
        <template slot-scope="scope">
          ${{scope.row.money}}
        </template>
      </el-table-column>
      <el-table-column
        prop="brush.phone"
        label="刷手联系方式">
      </el-table-column>
      <el-table-column
        prop="brush.email"
        label="刷手邮箱">
      </el-table-column>
      <el-table-column
        label="状态">
        <template slot-scope="scope">
          <template v-if="scope.row.status===1">审核中</template>
          <template v-else-if="scope.row.status===2">审核成功</template>
          <template v-else-if="scope.row.status===-1">审核失败</template>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        label="操作"
        width="270">
        <template slot-scope="scope">
          <div v-if="scope.row.status===1">
            <el-button
              size="mini"
              type="success"
              @click="auditWithdraw(scope.row.id,2)">同意
            </el-button>
            <el-button
              size="mini"
              type="success"
              @click="auditWithdraw(scope.row.id,-1)">拒绝
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total-elements="totalElements"
      :change-callback="getAccountBookWithdrawList"
      ref="page"></pagination>
  </div>
</template>

<script>
  import {getAccountBookWithdrawList, auditWithdraw} from '@/modules/brush/api/accountBook'
  import pagination from '@/components/pagination/index'

  export default {
    components: {pagination},
    name: 'user',
    data() {
      return {
        value: 1,
        loading: false,
        btnLoading: false,
        multipleSelection: [], // 选中数据-多选
        totalElements: 0, // 数据条数
        queryList: {
          status: 1,
        }, // 搜素数据
        tableData: [], // 表格数据
        addDialog: false, // 添加角色模态框
        form: {
          username: '',
          password: '',
          name: '',
          phone: '',
          email: '',
          status: 1 // 下拉框多选值
        }, // 添加用户数据
        formLabelWidth: '120px',
        options: [{value: 1, name: "审核中"}, {value: 2, name: "审核成功"}, {value: -1, name: "审核失败"}],
        editDialog: false, // 编辑角色模态框
        currentRow: {
          id: '',
          name: '',
          phone: '',
          email: '',
          roles: []
        } // 当前表格对象
      }
    },
    mounted() {
      this.getAccountBookWithdrawList()
    },
    methods: {
      handleSelectionChange(val) {
        this.multipleSelection = val
      },
      handleDelete(row) {
        this.multipleSelection.push(row)
        this.deleteRoles()
      },
      /*
       * 获取用户列表
       * */
      getAccountBookWithdrawList(number, pageSize) {
        this.loading = true
        getAccountBookWithdrawList(this.queryList.status,number, pageSize, this.queryList).then(response => {
          let data = response.obj
          console.log(data)
          this.totalElements = data.totalElements
          this.tableData = data.content
          setTimeout(() => {
            this.loading = false
          }, 500)
        }).catch(() => {
          this.loading = false
        })
      },
      /*
       * 禁用用户
       * */
      auditWithdraw(accountBookId, status) {
        let show = true;
        if(status === 2){
          show = false;
        }
        this.$confirm(show?'原因(必填)':'', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showInput:show,
        }).then(({ value }) => {
          this.loading = true
          auditWithdraw(accountBookId, status,value).then(response => {
            this.$message({
              message: response.msg,
              type: 'success',
              duration: 1000
            })
            this.$refs.page.refresh()
          }).catch(() => {
            this.loading = false
          })
        })
      },
      /*
       * 启用用户
       * */
      enableUser(id) {
        this.$confirm('是否启用该用户?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        }).then(() => {
          this.loading = true
          enableUser(id).then(response => {
            this.$message({
              message: response.msg,
              type: 'success',
              duration: 1000
            })
            this.$refs.page.refresh()
          }).catch(() => {
            this.loading = false
          })
        })
      },
      /*
       * 添加用户
       * */
      /*
       * 打开添加用户模态框
       * */
      openAddDialog() {
        this.addDialog = true
        this.getRoles()
      },
      /*
       * 关闭添加用户模态框
       * */
      closeAddDialog() {
        this.addDialog = false
        this.form = {
          username: '',
          password: '',
          name: '',
          phone: '',
          email: '',
          roles: [] // 下拉框多选值
        }
      },
      /*
       * 添加用户
       * */
      addUser() {
        this.loading = true
        this.btnLoading = true
        addUser(this.form).then(response => {
          this.$message({
            message: response.msg,
            type: 'success'
          })
          this.btnLoading = false
          this.closeAddDialog()
          this.$refs.page.refresh()
        }).catch(() => {
          this.btnLoading = false
          this.loading = false
        })
      },
      /*
       * 编辑用户
       * */
      /*
       * 打开编辑用户模态框
       * */
      openEditDialog(row) {
        this.currentRow.id = row.id
        this.currentRow.name = row.name
        this.currentRow.phone = row.phone
        this.currentRow.email = row.email
        this.currentRow.roles = []
        if (row.roles) {
          row.roles.forEach(item => {
            this.currentRow.roles.push(item.id)
          })
        }
        this.editDialog = true
        this.getRoles()
      },
      /*
       * 关闭编辑用户模态框
       * */
      closeEditDialog(row) {
        this.editDialog = false
      },
      /*
       * 编辑用户
       * */
      editUser() {
        this.loading = true
        this.btnLoading = true
        editUser(this.currentRow).then(response => {
          this.$message({
            message: response.msg,
            type: 'success'
          })
          this.btnLoading = false
          this.closeEditDialog()
          this.$refs.page.refresh()
        }).catch(() => {
          this.btnLoading = false
          this.loading = false
        })
      },
      /*
     * 刷新
     * */
      refresh() {
        this.$refs.page.refresh()
      },
      /*
      * 搜索
      * */
      search() {
        this.$refs.page.search()
      },
      /*
      * 重置
      * */
      reset() {
        this.queryList = {
        }
        this.$refs.page.search()
      }
    }
  }
</script>

<style scoped>
  body .el-table th.gutter {
    display: table-cell !important;
  }
  /*.filter-container{
    display: flex;
    align-items: center;
  }*/
</style>
